<!--
 * @author: sanbao
 * @Date: 2022-08-11 09:27:27
-->
<style lang='scss' scoped>
.mytable {
  margin: 20px;
  padding: 20px;
  box-sizing: border-box;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.5);
  border-radius: 5px;
  .templateimage {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    text-align: center;
  }
}
</style>

<template>
  <div class="mytable">
    <el-table :data="tableData" border max-height="500" style="width: 100%">
      <template v-for="(item, idnex) in tablelist">
        <!-- 序号 -->
        <el-table-column
          v-if="item.type == 'index'"
          :type="item.type"
          :label="item.label"
          width="60"
        />
        <!-- 正常内容 -->
        <el-table-column
          v-else-if="!item.type"
          :prop="item.prop"
          :label="item.label"
          :width="item.width"
          v-bind="item"
        >
        </el-table-column>
        <!-- avatar -->
        <el-table-column
          v-else-if="item.type == 'avatar'"
          :prop="item.prop"
          :label="item.label"
        >
          <template #default="scope">
            <img class="templateimage" :src="scope.row.avatar" alt="" />
          </template>
        </el-table-column>
        <!-- role -->
        <el-table-column
          v-else-if="item.type == 'role'"
          :prop="item.prop"
          :label="item.label"
        >
          <template #default="scope">
            <el-button type="primary" plain size="small">
              {{ scope.row.role[0].title }}
            </el-button>
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column
          v-else-if="item.type == 'action'"
          :prop="item.prop"
          :label="item.label"
        >
          <template #default="scope">
            <el-button
              size="small"
              v-for="(v, i) in item.list"
              :key="i"
              :type="v.type"
            >
              {{ v.name }}
            </el-button>
          </template>
        </el-table-column>
      </template>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      v-if="pager"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pager.currentPage"
      :page-sizes="pager.pageSizes"
      :page-size="pager.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pager.total"
    >
    </el-pagination>
  </div>
</template>

<script lang='ts'>
import { defineComponent, ref, reactive, toRefs, computed } from "vue";
export default defineComponent({
  props: {
    tableData: {
      type: Array,
      default: [],
    },
    tablelist: {
      type: Array,
      default: [],
    },
    pager: {
      type: Object,
    },
  },
  components: {},
  setup(props, { emit }) {
    const handleSizeChange = (size: number) => {
      emit("handleSizeChange", size);
    };
    const handleCurrentChange = (page: number) => {
      emit("handleCurrentChange", page);
    };
    return {
      handleSizeChange,
      handleCurrentChange,
    };
  },
});
</script>
